﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MPP.Product.Repository;
using MPP.Product.BusinessEntity;
using Microsoft.Practices.Unity;
using Mpp.Utility;

namespace MPP.Product.BusinessLogic
{
    public class MobilePhoneDomain
    {
        protected IRepository _respository;

        public  MobilePhoneDomain()
        {
            this._respository = DependencyInjectionContainer.UnityContainer.Resolve<IRepository>();
        }

        /// <summary>
        /// Saves the mobile phone.
        /// </summary>
        /// <param name="mobile">The mobile.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public MobilePhoneBE SaveMobilePhone(MobilePhoneBE mobile)
        {
            if (mobile == null) return null;

            if (mobile.Name == null || mobile.Name.Equals(string.Empty)) return null;

            if (mobile.NetworkSystem == null || mobile.NetworkSystem.Equals(string.Empty)) return null;

            if (mobile.Brand == null || mobile.Brand.Equals(string.Empty)) return null;

            if (mobile.FunctionItems != null &&mobile.FunctionItems.Count > 1 )
            {
                for (int i = 0; i < mobile.FunctionItems.Count-1; i++)
                {
                    for (int j = i+1; j < mobile.FunctionItems.Count; j++)
                    {
                        if (mobile.FunctionItems[i].Type==null || mobile.FunctionItems[j].Type ==null || mobile.FunctionItems[i].Type==mobile.FunctionItems[j].Type) return null;
                    }
                }
            }
            return this._respository.SaveMobilePhone(mobile);
        }



    }
}
